{template 'common/header'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/bootstrap-select/bootstrap-select.min.css" />
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            砍价
        </h3>
    </div>
    <div class="panel-body">
        <ul class="nav nav-tabs">
            <li role="presentation"><a href="{url 'site/entry/Service_class',array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">分类</a></li>
            <li role="presentation"><a href="{url 'site/entry/Service',array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">列表</a></li>
            <li role="presentation"><a href="{url 'site/entry/Teacher',array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">名师</a></li>
            <li role="presentation"><a href="{url 'site/entry/Service_team',array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">开课</a></li>
            <li role="presentation"><a href="{url 'site/entry/School',array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">分校管理</a></li>
            <li role="presentation" class="active"><a>砍价</a></li>
            <li role="presentation"><a href="{url 'site/entry/Mall',array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">商城</a></li>
        </ul>
        <div class="ibox-content">
            <form action="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}" id="searchform" method="get">
                <input type="hidden" class="form-control" name="c" value="site">
                <input type="hidden" class="form-control" name="a" value="entry">
                <input type="hidden" class="form-control" name="do" value="{$_GPC['do']}">
                <input type="hidden" class="form-control" name="m" value="{$_GPC['m']}">
                <input type="hidden" class="form-control" name="version_id" value="{$_GPC['version_id']}">
                <div class="row" style="padding: 0 15px;">
                    <div class="col-sm-3">
                        <select class="selectpicker show-tick form-control bs-select-hidden" data-live-search="true" name="pid" style="width: 50%;">
                            <option value="0" hassubinfo="true">请选择课程</option>
                            {loop $class $index $vo}
                            <option value="{$vo['id']}" {if $vo['id']==$pid}selected{/if}>{$vo['name']}</option>
                            {/loop}
                        </select>
                    </div>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" placeholder="标识" name="mark" value="{$mark}">
                    </div>
                    <div class="col-sm-2">
                        <button type="submit" class="btn btn-default " style="margin-right:5px;">查询</button>
                        <a class="btn btn-primary" href="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'edit','version_id'=>$_GPC['version_id'])}">增加</a>
                    </div>
                </div>
            </form>
        </div>
        <form action="" method="post" class="form-horizontal form">
            <input type="hidden" name="token" value="{$_W['token']}">

            <div class="table-responsive panel-body">
                <table class="table-striped table-bordered table-hover dataTables-example table">
                    <thead class="navbar-inner">
                    <tr>
                        <th>课程</th>
                        <th>标识</th>
                        <th>截止时间</th>
                        <th>已有人数</th>
                        <th>排序</th>
                        <th>状态</th>
                        <th>添加时间</th>
                        <th style="text-align:right;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $index $item}
                    <tr>
                        <td><div class="type-parent">{$item['name']}</div></td>
                        <td><div class="type-parent">{$item['mark']}</div></td>
                        <td><div class="type-parent">{$item['end_time']}</div></td>
                        <td><div class="type-parent">{$item['is_member']}/{$item['member']}</div></td>
                        <td><div class="type-parent">{$item['sort']}</div></td>
                        <td><div class="type-parent" style="width: 52px;height: 32px;">
                            {if $item['status']==1}
                            <input type="checkbox" checked class="js-switch" value="1" name="status" data-id="{$item['id']}" data-name="status">
                            {else}
                            <input type="checkbox" class="js-switch" name="status" value="1" data-id="{$item['id']}" data-name="status">
                            {/if}
                        </div></td>
                        <td><div class="type-parent">{$item['createtime']}</div></td>
                        <td style="text-align:right;">
                            <a href="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'edit','id'=>$item['id'])}" class="btn btn-primary btn-xs edit"><i class="fa fa-edit"></i>修改</a>
                            <a class="btn btn-danger btn-xs delete" data-id="{$item['id']}"><i class="fa fa-edit"></i>删除</a>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                <div style="text-align: right;">
                    {$pager}
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js","../addons/{php echo $_GPC['m']}/resource/bootstrap-select/bootstrap-select.min.js"],function(){
        $('.selectpicker').selectpicker();
        $(function(){
            //改变状态
            $(".js-switch").change(function(){
                var status;
                var that=$(this);
                if($(this).is(":checked")){
                    status=1;
                }else{
                    status=0;
                }
                var id=$(this).attr("data-id");
                var name=$(this).attr("data-name");
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'statuschange','version_id'=>$_GPC['version_id'])}",
                    data:{id:id,status:status,name:name},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            that.prop("checked",!that.is(":checked"));
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            })
            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '确定删除吗?',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'delete','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
        })
    })
</script>
{template 'common/footer'}